﻿using System;
using System.Collections.Generic;
using System.Text;
using Sinacor.Service.Infra.AuthorizationService.BusinessEntity;
using Sinacor.Infra.Service.Security.Authorization;

namespace Sinacor.Service.Infra.AuthorizationService.BusinessLogic
{
    public class Menu
    {
        public List<Company> RetrieveCompanies()
        {
            List<Company> companys = ResourceAccess.Menu.RetrieveCompanies(AuthorizationContext.Current.LoginName, AuthorizationContext.Current.UserId);
            return companys; 
        }

        public List<Module> RetrieveModules(int companyId)
        {
            List<Module> modules = ResourceAccess.Menu.RetrieveModules(AuthorizationContext.Current.UserId, companyId);
            foreach (Module module in modules)
            {
                module.Items = ResourceAccess.Menu.RetrieveMenu(module.Id, AuthorizationContext.Current.UserId, companyId);
                module.Roles = ResourceAccess.Menu.RetrieveRoles(module.Id, AuthorizationContext.Current.UserId, companyId);
            }
            return modules;
        }

		public bool CheckRolePermission(string role, string moduleId, int companyId)
		{
			return Sinacor.Infra.Service.Security.Authorization.AuthorizationContext.Current.CheckUserAccess(role, AuthorizationContext.Current.UserId, companyId, moduleId);
		}
	}
}